package cn.seczone.iast.agent;

import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;

/**
 * @author XieShaoping
 */
public class PreMain {

    //JVM 首先尝试在代理类上调用以下方法
    public static void premain(String agentArgs, Instrumentation inst) {
        inst.addTransformer(new MyTransformer());
    }

    public static void agentmain(String agentArgs, Instrumentation inst) throws UnmodifiableClassException {
        inst.addTransformer(new MyTransformer(), true);
        Class<?>[] cs = inst.getAllLoadedClasses();
        if (cs != null) {
            for (Class<?> c : cs) {
                if (!"com.example.webdemo.controller.TestController".equals(c.getName()) || c.isInterface() || c.isAnnotation() || c.isArray() || c.isEnum()) {
                    continue;
                }
                System.out.println(c.getName());
                inst.retransformClasses(c);
            }
        }
    }
}

